package com.ly.common.core.aop;

import com.ly.common.core.annotation.TenantLog;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.AfterThrowing;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.stereotype.Component;

import java.lang.reflect.Method;

/**
 * 租户日志-aop
 *
 * @author taoYan
 * @Date 2023/2/16 14:27
 **/
@Aspect
@Component
public class TenantLogAop {

    @Pointcut("@annotation(com.ly.common.core.annotation.TenantLog)")
    public void pointCut() {
    }

    @Around("pointCut()")
    public Object aroundMethod(ProceedingJoinPoint joinPoint) throws Throwable {
        // System.out.println("环绕通知>>>>>>>>>");
        MethodSignature signature = (MethodSignature) joinPoint.getSignature();
        Method method = signature.getMethod();
        TenantLog log = method.getAnnotation(TenantLog.class);
        if (log != null) {
            int opType = log.value();
            Integer logType = null;
            String content = null;
            Integer tenantId = null;
            // 获取参数
            if (logType != null) {
                // 保存系统日志
            }
        }
        return joinPoint.proceed();
    }

    @AfterThrowing("pointCut()")
    public void afterThrowing() throws Throwable {
        System.out.println("异常通知");
    }
}
